<script setup>
import { ref } from "vue";
import { useemployeeInfoStore } from "@/src-manager/stores/employeeInfo.js";
const employeeInfoStore = useemployeeInfoStore();


const employeeInfo = ref({
  ...employeeInfoStore.info,
});

const rules = {
  employeeName: [
    { required: true, message: "请输入用户昵称", trigger: "blur" },
    {
      pattern: /^\S{2,10}$/,
      message: "昵称必须是2-10位的非空字符串",
      trigger: "blur",
    },
  ],
  email: [
    { required: true, message: "请输入用户邮箱", trigger: "blur" },
    { type: "email", message: "邮箱格式不正确", trigger: "blur" },
  ],

  phoneNumber: [
    { required: true, message: "请输入手机号码", trigger: "blur" },
    {
      pattern: /^1[3-9]\d{9}$/,
      message: "手机号码格式不正确",
      trigger: "blur",
    },
  ],
};

import { updateemployeeInfoService } from "@/src-manager/api/employee.js";

import { ElMessage } from "element-plus";


const updateemployeeInfoModel = ref({

  phoneNumber: '',
  email: ''

})
const updateemployeeInfo = async () => {

  updateemployeeInfoModel.value.phoneNumber = employeeInfo.value.phoneNumber;
  updateemployeeInfoModel.value.email = employeeInfo.value.email;

  let result = await updateemployeeInfoService(updateemployeeInfoModel.value);
  if (result.code === 200) {


    employeeInfoStore.setInfo(employeeInfo.value);
    ElMessage.success("修改成功");

  } else {
    ElMessage.error("修改失败");
  }

};

</script>
<template>
  <el-card class="page-container">
    <template #header>
      <div class="header">
        <span>修改密码</span>
      </div>
    </template>
    <el-row>
      <el-col :span="12">
        <el-form :model="employeeInfo" :rules="rules" label-width="100px" size="large">
          <el-form-item label="登录名称">
            <el-input v-model="employeeInfo.employeeName" disabled></el-input>
          </el-form-item>

          <el-form-item label="手机号码" prop="nickname">
            <el-input v-model="employeeInfo.phoneNumber"></el-input>
          </el-form-item>
          <el-form-item label="用户邮箱" prop="email">
            <el-input v-model="employeeInfo.email"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="updateemployeeInfo()">提交修改</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </el-card>
</template>
